package control
{
    import flash.display.Sprite;
    
    import control.IProcessInformer;

    /**
     * Simple progress bar is a line with fixed widht, height and custom color
     */
    public class ProgressBar extends Sprite implements IProcessInformer
    {
        public static const WIDTH: Number = 80;
        public static const HEIGHT: Number = 15;
        public static const COLOR: uint = 0x0000FF;
        
        public function ProgressBar()
        {
            super();
            addChild(filline = new Sprite());
            addChild(borderline = new Sprite());
        }

	
        //------------------------------
	// Color
        //------------------------------
        
        private var _color: uint = COLOR;
        
        /**
         * ProgressBar color
         */
        public function set color(value:uint):void
        {
            if (value == _color)
	        return;
            _color = value;
            redraw();
        }
        
        public function get color():uint 
        {
            return _color;
        }

	
        //------------------------------
	// Percent
        //------------------------------
        
        private var _percent: Number = 0.0;
	
        /**
         * Progress percent
         */
        public function set percent (value:Number):void
        {
            _percent = value;
            filline.scaleX = _percent;
        }
      
        public function get percent ():Number
        {
            return _percent;
        }


	//------------------------------------------------------------------
	//
	//  Private logic
	//
	//------------------------------------------------------------------
	
	private var filline: Sprite;
        private var borderline: Sprite;

        private function redraw():void 
        {
            borderline.graphics.lineStyle(1, _color);
            borderline.graphics.drawRect(0, 0, WIDTH, HEIGHT);
            filline.graphics.beginFill(_color);
            filline.graphics.drawRect(0, 0, WIDTH, HEIGHT);
            filline.scaleX = _percent;
        }
      
    }
}